package com.zkingsoft.actions.visitor;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.model.Article;
import com.zkingsoft.model.ArticleType;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.ArticleService;
import com.zkingsoft.services.ArticleTypeService;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-11-11 10:23
 */
@Controller
@RequestMapping(value = "/arInterface")
public class ArController extends BaseController {

	@Resource
	private ArticleService currentService;
	@Resource
	private ArticleTypeService arTypeService;

	/**
	 * 
	 * @Description:根据分类名称查询分类下所有文章
	 * @auther:罗袁宏
	 * @param articleTypeName
	 *            文章类型名称
	 * @return 返回类型 :AjaxResult
	 * @date:2016年11月11日
	 */
	@RequestMapping(value = "/ar")
	public @ResponseBody AjaxResult ar(Article ar, PaginationVO pageVo) {
		List<Article> arList = currentService.findInPage(ar, pageVo);
		// 判断是否有该文章类型的文章
		if (arList.size() <= 0) {
			return new AjaxResult(AjaxResult.STATUS_OK, null, "暂无数据");
		}
		return new AjaxResult(AjaxResult.STATUS_OK, null, "所有文章信息", arList, currentService.findTotal(ar));
	}

	/**
	 * @Description:根据文章id查询文章内容
	 * @auther:罗袁宏
	 * @param id
	 *            文章ID
	 * @return 返回类型 :AjaxResult
	 * @date:2016年11月11日
	 */
	@RequestMapping(value = "/arInfo")
	public @ResponseBody AjaxResult arInfo(Article article) {
		// 判断是否传参
		if ("".equals(article.getId())) {
			return new AjaxResult(AjaxResult.STATUS_ERR, null, "参数不全");
		}
		Article ar = currentService.findById(article.getId());
		// 判断该文章是否存在
		if (ar == null) {
			return new AjaxResult(AjaxResult.STATUS_ERR, null, "暂无数据");
		}
		List<Article> arList = new ArrayList<Article>();
		arList.add(ar);
		return new AjaxResult(AjaxResult.STATUS_OK, null, "文章信息", arList, arList.size());
	}
}